package cn.tedu.straw.portal.util;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import lombok.experimental.Accessors;

@Data
//chain=true 使用链式
@Accessors(chain=true)
public class R<T> {
  //  public static final Integer ERR_PARAM_VALIDATION =6 ;
    private Integer state;

    private String message;
    //T 类型占位符
    private T data;
    public static R ok(){
        return new R().setState(State.OK);
    }
    public static<T> R ok(T data){
        return new R().setState(State.OK).setData(data);
    }
    public static R failure(Integer status,String message){
        return new R().setState(status).setMessage(message);
    }

    public static R failure(Integer status,Throwable e){
        return new R().setState(status).setMessage(e.getMessage());
    }

    public interface State{
        int OK=2000;
        int ERR_INVITE_CODE=4010;
        int ERR_CLASS_DISABLED=4020;
        int ERR_PHONE_DUPLICATE=4030;
        int ERR_INSERT=4040;
        int ERR_PARAM_VALIDATION=4050;
        int ERR_FILE_UPLOAD_EMPTY=4060;
        int ERR_FILE_UPLOAD_SIZE=4070;
        int ERR_FILE_UPLOAD_TYPE=4080;
        int ERR_FILE_UPLOAD_IO=4090;
        int ERR_FILE_UPLOAD_STATE=4100;
        int ERR_QUESTION_NOT_FOUND=4110;
        int ERR_ANSWER_NOT_FOUND=4120;
    }
}
